/**
 * 
 */
package com.ssm.util;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.config.Configuration;

/**
 * 
 * @author 危文涛<245108903@qq.com>
 * @version 2016年3月19日 下午7:07:36
 *
 */
public class EhcacheUtil {  
	  
    public static CacheManager manager =CacheManager.create(EhcacheUtil.class.getClassLoader().getResourceAsStream("ehcacheConfig.xml"));//.create("classpath:ehcacheConfig.xml"); 
    
    public static Object get(String cacheName, Object key) {  
        Cache cache = manager.getCache(cacheName);  
        if (cache != null) {  
            Element element = cache.get(key);  
            if (element != null) {  
                return element.getObjectValue();  
            }  
        }  
        return null;  
    }  
  
    public static void put(String cacheName, Object key, Object value) {  
        Cache cache = manager.getCache(cacheName);  
        if (cache != null) {  
            cache.put(new Element(key, value));  
        }  
    }  
  
    public static boolean remove(String cacheName, Object key) {  
        Cache cache = manager.getCache(cacheName);  
        if (cache != null) {  
            return cache.remove(key);  
        }  
        return false;  
    }   
  
}  